package cn.xingzhe.monster.user.infrastructure.persistence.converter;

import cn.xingzhe.monster.user.domain.model.PermissionModel;
import cn.xingzhe.monster.user.infrastructure.persistence.entity.PermissionEntity;

/**
 * 权限实体转换器
 * 负责 PermissionEntity 和 PermissionModel 之间的转换
 *
 * @author System
 * @version 1.0.0
 * @since 2024-01-01
 */
public class PermissionEntityConverter {

    /**
     * Entity 转 Model
     *
     * @param entity 实体
     * @return 领域模型
     */
    public static PermissionModel toModel(PermissionEntity entity) {
        if (entity == null) {
            return null;
        }
        return PermissionModel.builder()
                .id(entity.getId())
                .permissionCode(entity.getPermissionCode())
                .permissionName(entity.getPermissionName())
                .resource(entity.getResource())
                .action(entity.getAction())
                .description(entity.getDescription())
                .createTime(entity.getCreateTime())
                .updateTime(entity.getUpdateTime())
                .build();
    }

    /**
     * Model 转 Entity
     *
     * @param model 领域模型
     * @return 实体
     */
    public static PermissionEntity toEntity(PermissionModel model) {
        if (model == null) {
            return null;
        }
        return PermissionEntity.builder()
                .id(model.getId())
                .permissionCode(model.getPermissionCode())
                .permissionName(model.getPermissionName())
                .resource(model.getResource())
                .action(model.getAction())
                .description(model.getDescription())
                .createTime(model.getCreateTime())
                .updateTime(model.getUpdateTime())
                .build();
    }
}

